package cn.com.xjnt.vas.manage.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.frameworks.core.repository.BaseRepository;
import com.frameworks.core.service.AbstractBaseService;
import com.google.common.collect.Lists;

import cn.com.xjnt.vas.manage.domain.entity.Region;
import cn.com.xjnt.vas.manage.repository.RegionRepository;
import cn.com.xjnt.vas.manage.service.RegionService;

/** 
* 类说明：
* @author 作者 LUXIN
* @version 创建时间：2016年5月5日 上午11:05:16 
*/
@Service
@Transactional
public class RegionServiceImpl extends AbstractBaseService<Region, Long> implements RegionService {
    @Autowired
    private RegionRepository regionRepository;
    
    @Override
    protected BaseRepository<Region, Long> getBaseRepository() {
        return regionRepository;
    }

    @Override
    public void save(Region entity) {
        super.saveOrUpdate(entity);
    }

    @Override
    public void update(Region entity) {
        super.saveOrUpdate(entity);
    }

    @Override
    public List<Region> findByParentId(Long parentId) {
        return regionRepository.findByParentId(parentId);
    }
    
    /**
     * 获取该地域id，同一父id下的平级的所有地域
     * @param id
     * @return
     */
    @Override
    public List<Region> findAllRegionsAtSameLevelById(Long id) {
        List<Region> lists = Lists.newArrayList();
        lists = regionRepository.findAllRegionsAtSameLevelById(id);
        return lists;
    }
}
 